<template>
	<!-- 绑定手机号 -->
	<view>
		<view class="" style="padding: 26rpx 30rpx 0rpx ;">
			<view class="" style="padding-bottom: 36rpx;">
				<x-cell :leftslot="true">
					<view class="d-flex" slot="lefttext">
						<view class="" style="margin-right: 38rpx;">
							电话号码
						</view>
						<view class="" style="">
							<input type="text" v-model="phonenum" />
						</view>
					</view>
				</x-cell>
			</view>
			<u-line color="info" border-style="solid" />
			<view class="" style="padding: 26rpx 0rpx 34rpx;">
				<x-cell :leftslot="true" :rightslot="true">
					<view class="d-flex" slot="lefttext">
						<view class="" style="margin-right: 38rpx;">
							验证码
						</view>
						<view class="" style="color: #B7B7B7;">
							<input type="text" v-model="codevalue" />
						</view>
					</view>
					<view class=" d-flex-yCenter-ju textColor-white " slot="righttext" style="width: 75px;height: 30px;
						background: #FF890B;border-radius: 6px;font-size: 24rpx;" @click="codenum">
						<view class="" v-if="code">
							获取验证码
						</view>
						<view class="" v-if="!code">
							{{time}}
						</view>
					</view>
				</x-cell>
			</view>
			<u-line color="info" border-style="solid" />	
			<view class="" style="color: #989898;margin-top: 30rpx;font-size: 24rpx;">
				温馨提示：您还未绑定手机号，输入手机号， 点击获取验证码可以收到有验证码的短信 进行绑定，绑定成功后才可进行更换手机号
			</view>
			<!-- <view class="" style="margin-top: 106rpx;" @click="getTophone">
				<x-button title="下一步"></x-button>
			</view> -->
			<view class="" style="margin-top: 106rpx;">
				<x-button title="绑定" bgColor="#B7B7B7" @btnClick="getTophone"></x-button>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		sendcode,
		mobile//			// 绑定手机号
	} from '@/config/apiRouter.js'
	export default {
		data() {
			return {
				code: true,
				time: '', //验证码倒计时
				phonenum: '', //手机号
				timer: '',
				codevalue: '', //填写验证码的值

			}
		},
		onLoad(options) {

		},
		methods: {
			// 绑定手机号
			getTophone() {
				mobile({
					phone: this.phonenum,
					code: this.codevalue
				}).then(res => {
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
					// 绑定成功返回我的界面
					uni.switchTab({
						url:'../../pages/my/my'
					})
					console.log(res, '绑定手机号成功')
				})
			},
			// 获取验证码
			codenum() {
				if (this.code) {
					this.code = !this.code;
					this.timer = setInterval(() => {
						this.time--;
						if (this.time == 0) {
							this.code = true;
							this.time = 60;
						}
					}, 1000)


					sendcode({
						mobile: this.phonenum,
						// mobile: '18338089712',
					}).then(res => {
						this.time = res.data.resend_time;
						uni.showToast({
							title: res.msg
						})
						if (this.codevalue) {
							this.code = true;
							clearInterval(this.timer); //清除循环定时器
						}

					})


				}
			},


		}
	}
</script>

<style>

</style>
